<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$ui = new UI();
$tpl = new Template2();
include_once( "class/function_3d.php" );
$tpl->load(array("menu" => "6h_menu.htm","main" => "history.htm", "news" => "news.htm"));
$tpl->show( "menu" );
$conf = new Config();
if ($conf->get("calcbet") == 1)
{
    $ui->showErrorPage("<p class=error>颁奖过帐中，请稍後再使用本功能！</p>");
    exit();
}
$news = $conf->Get("news");
$tpl->set("newsmessage", $news);
$tpl->show("news");
$tmp = "";
$list1 = "";
$sum_amount = 0;
$sum_result = 0;
$sum_result_tw = 0;
$sum_bingo = 0;
$sum_back1 = 0;
$pagecount = $conf->get("page_max_count");
$postTime = $conf->get("paper_post_bet");
if (date("Hi") <= $postTime)
{
    $todayInt = strtotime("-1 day");
    $today = date("Y-m-d", $todayInt);
}
else
{
    $todayInt = time();
    $today = date("Y-m-d", $todayInt);
}
$minday = getPaperMinDate(0 - 1);
$today = date("Y-m-d");
$dateTempM = date("m", $todayInt);
$dateTempD = date("d", $todayInt);
$dateTempW = date("w", $todayInt);
$dateTempY = date("Y", $todayInt);
if ($dateTempW == 0)
{
    $secThisWeek1 = mktime(0, 0, 0, $dateTempM, $dateTempD - 6, $dateTempY);
}
else
{
    $secThisWeek1 = mktime(0, 0, 0, $dateTempM, $dateTempD - $dateTempW + 1, $dateTempY);
}
$calThisWeek1 = date("Y-m-d", $secThisWeek1);
$calLastWeek1 = date("Y-m-d", $secThisWeek1 - 604800);
$calLastWeek2 = date("Y-m-d", $secThisWeek1 - 1);
$lastday = date("Y-m-d", strtotime($today) - 86400);
$minday = getPaperMinDate(0 - 1);
$begin = getvar("begin") == "" ? $calThisWeek1 : getvar("begin");
$end = getvar("end") == "" ? $today : getvar("end");
$check = getvar("begin") == "" ? "2" : getvar("check");
$tpl->set(array("today" => $today, "minday" => $minday, "calThisWeek1" => $calThisWeek1, "calLastWeek1" => $calLastWeek1, "calLastWeek2" => $calLastWeek2, "d", "begin" => $begin, "end" => $end));
$today = max($end, $minday);
$minday = max($begin, $minday);
$lottos = lotto::gethistory($minday, $today);
if (0 < count($lottos))
{
    $i = 0;
    while ($i < count($lottos))
    {
        $id = $lottos[$i];
        $lotto = new lotto($id);
        if ($begin < getPaperMinDate(0 - 1) && $end < getPaperMinDate(0 - 1))
        {
            $tmp .= "<tr ><td colspan=5 align=center>查询日期小於可看最小报表日</td></tr>";
        }
        else
        {
            $tmp .= "<tr class=td2>";
            $rs = getdb("select sum(amount),sum(b1),sum(a1) from bet where user_id=" . $_SESSION['uid'] . " and lotto_id=" . $id);
            $sum_a = $rs->f[0];
            $sum_r = $rs->f[1];
            $back1 = $rs->f[2];
            if ($sum_a == 0)
            {
                $tmp .= "<td nowrap><font color=#cc0000>" . $lotto->data['open'] . "</font></td>";
                $tmp .= "<td nowrap align=left><font color=#cc0000>" . d3($lotto->data['round']) . "</font></td>";
            }
            else
            {
                $tmp .= "<td nowrap><a href='?op=member&fp=view&lotto_id=" . $id . "'><font color=#cc0000><b>" . $lotto->data['open'] . "</b></font></a></td>";
                $tmp .= "<td nowrap align=left><a href='?op=member&fp=view&lotto_id=" . $id . "'><font color=#cc0000><b>" . d3($lotto->data['round']) . "</b></font></a></td>";
            }
            $tmp .= "<td align=left>" . $sum_a;
            $tmp .= "<td align=left>" . sprintf("%.2f", $back1);
            $tmp .= "<td align=left>" . say_numbercolor($sum_r);
            $sum_amount += $sum_a;
            $sum_result += $sum_r;
            $sum_back1 += $back1;
        }
        ++$i;
    }
}
else
{
    $tmp .= "<tr class=td2><td colspan=5 align=center>选择之日期区间无资料</td></tr>";
}
$slcList = "";
$slcList = "<script>\r\n  function chgHisUrl(oObj){\r\n    _showGameType = oObj.value;\r\n    if(_showGameType == -1){window.top.mainFrame.location.replace('?op=member_3d&fp=history_all');}\r\n    else if(_showGameType == 0){\r\n      window.top.leftFrame.location.replace('?op=member&fp=account');\r\n      window.top.mainFrame.location.replace('?op=member&fp=history');\r\n    }";
if ($g_init_mode_3d)
{
    $slcList .= "else if(_showGameType >= 20){\r\n              window.top.leftFrame.location.replace('?op=member_5h&fp=account&gametype='+_showGameType);\r\n              window.top.mainFrame.location.replace('?op=member_5h&fp=history&gametype='+_showGameType);\r\n            }\r\n            else{\r\n              window.top.leftFrame.location.replace('?op=member_3d&fp=account&gametype='+_showGameType);\r\n              window.top.mainFrame.location.replace('?op=member_3d&fp=history&gametype='+_showGameType);\r\n            }";
}
$slcList .= "\r\n  }\r\n</script>\r\n";
$slcList .= "<div class=\"col-sm-8\"><select class=\"form-control\" name=\"showGameType\" id=\"showGameType\" onchange=\"javascript:chgHisUrl(this);\">";
$slcList .= "<option class=\"paperall\" value=\"-1\">全部</option>";
if (!$g_init_mode_3d)
{
    foreach ($g_gametype_3d as $key => $value)
    {
        if ($key == 0)
        {
            continue;
        }
        unset($g_gametype_3d[$key]);
    }
}
foreach ($g_gametype_3d as $key => $val)
{
    $en = $val['en'];
    if ($key == 0)
    {
        $slced = "selected=\"selected\"";
    }
    else
    {
        $slced = "";
    }
    if ($g_menu_enabled[$key])
    {
        $slcList .= "<option class=\"paper{$en}\" value=\"{$key}\" {$slced} >";
        /*if ($key == 20)
        {
            $slcList .= "４+１码◎";
        }
        else if (20 < $key)
        {
            $slcList .= "八码◎";
        }
        else if ($key && $g_5number_3d)
        {
            $slcList .= getShow35($key) ? "五码◎" : "三码◎";
        }*/
        $slcList .= $val['ch'] . "</option>";
    }
}
$slcList .= "</select></div>";
$tpl->set("slcList", $slcList);
$tpl->set("list0", $tmp);
$tpl->set("sum_amount", $sum_amount);
$tpl->set("sum_result", say_numbercolor($sum_result));
$tpl->set("sum_back1", sprintf("%.2f", $sum_back1));
$tpl->set("sum_all", say_numbercolor($sum_result + $sum_back1));
$tpl->show("main");
echo "\r\n\r\n";
?>